<?php

namespace app\admin\controller;

use app\BaseController;
use app\common\job\MultiJob;
use app\common\job\SingleJob;
use think\App;
use think\facade\Queue;

/**
 * think-queue任务
 * https://github.com/top-think/think-queue
 *
 * //// 发布任务
 * think\facade\Queue::push($job, $data = '', $queue = null)
 * think\facade\Queue::later($delay, $job, $data = '', $queue = null)
 *
 * //// 监听任务
 * &> php think queue:listen
 * &> php think queue:work
 *
 * Class JobController
 * @package app\admin\controller
 * @author ^2_3^王尔贝
 */
//class JobController extends EndController
class JobController extends BaseController
{
    public function __construct(App $app)
    {
        parent::__construct($app);
    }

    /**
     * 任务发布(push)
     * @return \think\response\Json
     * @author ^2_3^王尔贝
     */
    public function push()
    {
        $params = $this->request->param();
        $params['developer'] = "cyb";
        $params['module'] = 'think-queue';

        Queue::push(SingleJob::class, $params);
        lo('[JobController]_push');
        return retJson('', 0, ['tips' => 'think-queue, push job']);
    }

    /**
     * 任务发布(later)
     * @return \think\response\Json
     * @author ^2_3^王尔贝
     */
    public function later()
    {
        $params = $this->request->param();
        $params['developer'] = "cyb";
        $params['module'] = 'think-queue';

        Queue::later('10', 'app\common\job\MultiJob@task1', $params);
        lo('[JobController]_later');
        return retJson('', 0, ['tips' => 'think-queue, later job']);
    }
}